package com.ymy.thinking.in.spring.dependency.injection;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * 基于 Java 注解的依赖注入
 *
 * @author Ringo
 * @date 2021/9/29 0:29
 */
public class AnnotationDependencySetterInjectionDemo {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AnnotationDependencySetterInjectionDemo.class);
        System.out.println(applicationContext.getBean(UserHolder.class));
    }

    @Bean
    public User user() {
        User user = new User();
        user.setName("李白");
        user.setAge(19);
        return user;
    }

    @Bean
    public UserHolder userHolder(User user) {
        return new UserHolder(user);
    }

}
